package com.example.dao.impl;

import com.example.controller.Employee;
import com.example.dao.EmpDao;
import com.example.utils.XmlParserUtils;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

@Component
public class EmpDaoImpl implements EmpDao {
    //通过 EmpImp 类来实现 EmpDao 接口的 getEmplist() 方法


    @Override
    public List<Employee> emplist() {

        //读取xml文件，解析出员工列表
        String filePath = this.getClass().getClassLoader().getResource("emp.xml").getFile();
        //解析xml文件
        List<Employee> employeeList = null;
        try {
            employeeList = XmlParserUtils.parse(filePath, Employee.class);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }

        return employeeList;
    }
}
